<?php
    include_once("../action/checkAuthenticationAction.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Quản lý trạng thái sản phẩm</title>
	<?php 
        include("import-css.php");
        include("../util/constant.php");
        include("../util/message.php");
    ?>
    
</head>
<body>
	<?php include("header.php");?>
<form id="form" method="post">
	<div class="container-fluid">
		<div class="row-fluid">
			<?php 
                include("menu.php");
                include_once("../service/newsletterService.php");
            ?>
			<div id="content" class="span10">
                <div id="msg" class="center alert"></div>
                <div class="row-fluid sortable">
    				<div class="box span12">
                    	<div class="box-header well" data-original-title>
                        	<form id="form" target="_blank">
                                    <input type="button" class="btn btn-primary" onClick="submitForm('form', '../action/exportNewsletterAction.php', 'post')" value="Xuất excel"/>
                                </form>
    					</div>
    					<div class="box-content">
                            
                            <table class="table table-striped table-bordered bootstrap-datatable datatable">
                                <thead>
                                    <tr>
                                        <th>STT</th>
                                        <th>Email</th>
                                        <th>Chức năng</th>
                                    </tr>
                                 </thead>   
                                 <tbody>
                                 	<?php

										
										$newsletters = findAllNewsletters();
										$count = 1;
										
										while($row = mysql_fetch_array($newsletters)){											
                                    ?>
                                        <tr id="row<?php echo $count;?>">
                                            <td><?php echo $count;?></td>
                                            <td><?php echo $row["NLE_EMAIL"];?></td>
                                            <td>
                                            	<?php
													$require_perm = array("delete newsletter");
													if(authUtil($require_perm,$perm_array,true)){
												?>
                                                    <a class="btn btn-danger" href="#" onclick="if(confirmDelete()) deleteNewsletter('row<?php echo $count++;?>',<?php  echo $row["NLE_ID"];?>);">
                                                        <i class="icon-trash icon-white"></i> 
                                                        Xóa
                                                    </a>
                                                <?php
													}
                                                ?>
                                            </td>
                                        </tr>
                                    <?php
										}
                                    ?>
                                 </tbody>
                             </table>    
    					</div>
    				</div><!--/span-->
    			</div><!--/row-->
            </div><!-- end of content -->
        </div><!-- end of row-fluid -->
        <?php include("footer.php");?>
    </div><!-- container-fluid -->
    <?php include("import-js.php");?>
    <script>
		function deleteNewsletter(rowId, newsletterId){
			$.ajax({  
                type: "POST",  
                url: "../action/ajax/deleteNewsletterAction.php",  
                data: "newsletterId=" +  newsletterId,
                success: function(data) {  
                    if(data == <?php echo DELETE_SUCCESSFULLY;?>){
                        showMessage("<?php echo $messages["delteteNewsletterSuccessfully"];?>", "success");
						$("#" + rowId).remove();
                    } else{
                        showMessage("<?php echo $messages["delteteNewsletterStatusFailed"];?>", "error");
                    }
                }
            });
		}
	</script>
</form>
</body>
</html>